// SmartFarmSystem.java
package com.smartfarm;


import com.smartfarm.Celue.AvoidancePathStrategy;
import com.smartfarm.Celue.PathPlanner;
import com.smartfarm.Gongchang.AgriculturalMachine;
import com.smartfarm.Gongchang.MachineFactory;
import com.smartfarm.Gongchang.Seeder;
import com.smartfarm.Gongchang.Sprayer;
import com.smartfarm.Guanchazhe.EnvironmentSensor;
import com.smartfarm.Mingling.RemoteControl;
import com.smartfarm.Mingling.StartCommand;
import com.smartfarm.Zerenlian.EmergencyHandler;
import com.smartfarm.Zerenlian.FaultHandler;
import com.smartfarm.Zerenlian.ObstacleHandler;
import com.smartfarm.Zerenlian.SafetyHandler;
import com.smartfarm.Zhuangshiqi.AutoDiagnosisDecorator;
import com.smartfarm.Zhuangshiqi.GPSDecorator;

public class SmartFarmSystem {
    public static void main(String[] args) {
        System.out.println("=============== 智能农机系统启动 ===============");

        // 工厂方法模式测试
        System.out.println("\n[工厂方法模式] 创建农机设备:");
        MachineFactory seederFactory = new MachineFactory() {
            @Override
            public AgriculturalMachine createMachine() {
                return new Seeder();
            }
        };
        AgriculturalMachine seeder = seederFactory.createMachine();
        seeder.operate();

        // 观察者模式测试
        System.out.println("\n[观察者模式] 环境监测通知:");
        EnvironmentSensor sensor = new EnvironmentSensor();
        sensor.registerObserver(event -> System.out.println("[拖拉机] 收到: " + event));
        sensor.registerObserver(event -> System.out.println("[播种机] 收到: " + event));
        sensor.setSensorData("土壤湿度达到85%");

        // 策略模式测试
        System.out.println("\n[策略模式] 路径规划算法:");
        PathPlanner planner = new PathPlanner();
        planner.setStrategy(new AvoidancePathStrategy());
        planner.executePathPlanning();

        // 责任链模式测试
        System.out.println("\n[责任链模式] 异常事件处理:");
        SafetyHandler chain = new ObstacleHandler();
        SafetyHandler faultHandler = new FaultHandler();
        SafetyHandler emergencyHandler = new EmergencyHandler();

        chain.setNextHandler(faultHandler);
        faultHandler.setNextHandler(emergencyHandler);

        chain.handleRequest("检测到前方障碍物");
        chain.handleRequest("发动机故障警告");

        // 命令模式测试
        System.out.println("\n[命令模式] 设备远程控制:");
        RemoteControl control = new RemoteControl();
        control.setCommand(new StartCommand(seeder));
        control.pressButton();
        //装饰器模式
        System.out.println("\n[装饰器模式] 动态扩展农机功能:");

        AgriculturalMachine basicSprayer = new Sprayer();


        AgriculturalMachine gpsSprayer = new GPSDecorator(basicSprayer);
        System.out.println("基础喷药机升级GPS版:");
        gpsSprayer.operate();


        AgriculturalMachine diagSprayer = new AutoDiagnosisDecorator(basicSprayer);
        System.out.println("\n 基础喷药机升级自诊断版:");
        diagSprayer.operate();


        AgriculturalMachine premiumSprayer = new AutoDiagnosisDecorator(new GPSDecorator(new Sprayer()));
        System.out.println("\n喷药机完全升级版:");
        premiumSprayer.operate();
        System.out.println("\n=============== 系统运行结束 ===============");
    }
}


